﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using K.EnterpriseLibary.Entity;
using Webdiyer.WebControls.Mvc;

namespace K.ClientOfMVC.Controllers
{
    public class NameController : BaseController
    {

        public NameController()
            : base()
        {
            //定义本Controller下的页面公共信息

        }
        //
        // GET: /Name/

        /// <summary>
        /// 基本信息页面
        /// </summary>
        /// <returns></returns>
        public ActionResult StepOfBaseData()
        {
            mainModel.appInfo.SiteTitle = "输入宝宝姓名基本资料";
            ViewData["MainModel"] = mainModel;
            List<SelectListItem> strucListYear = new List<SelectListItem>();


            for (int i = 0; i < 10; i++)
            {
                int intYear = 2010;
                strucListYear.Add(new SelectListItem() { Text = (intYear + i).ToString(), Value = (intYear + i).ToString()});                 
            }

            ViewData["BirthdayYear"] = new SelectList(strucListYear, "Value", "Text");

            
            List<SelectListItem> strucListMonth = new List<SelectListItem>();
            for (int i = 0; i < 12; i++)
            {
                int intMonth = 1;
                strucListMonth.Add(new SelectListItem() { Text = (intMonth + i).ToString(), Value = (intMonth + i).ToString()});
            }
            ViewData["BirthdayMonth"] = new SelectList(strucListMonth,"Value","Text");


            List<SelectListItem> strucListDay = new List<SelectListItem>();
            for (int i = 0; i < 31; i++)
            {
                int intDay = 1;
                strucListDay.Add(new SelectListItem() { Text = (intDay + i).ToString(), Value = (intDay + i).ToString() });
            }
            ViewData["BirthdayDay"] = new SelectList(strucListDay, "Value", "Text");

            List<SelectListItem> strucList = new List<SelectListItem>();
            strucList.Add(new SelectListItem() { Text = "双字", Value = "2", Selected = true });
            strucList.Add(new SelectListItem() { Text = "单字", Value = "1", Selected = false });
            strucList.Add(new SelectListItem() { Text = "叠字", Value = "3", Selected = false });
            ViewData["NameStruc"] = new SelectList(strucList, "Value", "Text");

            List<SelectListItem> knowWordList = new List<SelectListItem>();
            knowWordList.Add(new SelectListItem() { Text = "已知第一字", Value = "1", Selected = true });
            knowWordList.Add(new SelectListItem() { Text = "已知第二字", Value = "2", Selected = false });
            ViewData["KnowWord"] = new SelectList(knowWordList, "Value", "Text");

            return View();
        }

        [HttpPost]
        public ActionResult StepOfBaseData(string username)
        {
            return Redirect("StepOfCondition"); 
        }

        public ActionResult StepOfSex()
        {
            mainModel.appInfo.SiteTitle = "第二步，设定名字结构";
            ViewData["MainModel"] = mainModel;
            return View();
        }

        [HttpPost]
        public ActionResult StepOfSex(string sex)
        {
            return Redirect("StepOfStructure"); 
        }

        public ActionResult StepOfStructure()
        {
            mainModel.appInfo.SiteTitle = "第二步，设定名字结构";
            ViewData["MainModel"] = mainModel;
            List<SelectListItem> strucList = new List<SelectListItem>();
            strucList.Add(new SelectListItem() { Text="双字",Value="2",Selected=true});
            strucList.Add(new SelectListItem() { Text = "单字", Value = "1", Selected = false });
            strucList.Add(new SelectListItem() { Text = "叠字", Value = "3", Selected = false });
            strucList.Add(new SelectListItem() { Text = "单字固定", Value = "4", Selected = false });
            ViewData["NameStruc"] = new SelectList(strucList, "Value", "Text");
            return View();
        }

        [HttpPost]
        public ActionResult StepOfStructure(string nameStructure)
        {
            return Redirect("StepOfResult");
        }



        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult StepOfResult(int? page)
        {
            mainModel.appInfo.SiteTitle = "第二步，设定性别";
            ViewData["MainModel"] = mainModel;
            PagerInfo pager = new PagerInfo();
            pager.RecordCount = 1500;
            pager.PageSize = 10;
            pager.CurrentPageIndex = (page != null ? (int)page : 1);
            IList<NewsInfo> result = new List<NewsInfo>();
            for (int i = 0; i < 1500; i++)
            {
                NewsInfo info = new NewsInfo() { Id = i + 1, Title = "ASP.NET MVC 分页Helper效果演示", PostTime  = DateTime.Now };
                result.Add(info);
            }
            IEnumerable<NewsInfo> info2 = result.Where<NewsInfo>(id => id.Id > (pager.CurrentPageIndex - 1) * pager.PageSize && id.Id <= pager.CurrentPageIndex * pager.PageSize);
            PagerQuery<PagerInfo, IEnumerable<NewsInfo>> query = new PagerQuery<PagerInfo, IEnumerable<NewsInfo>>(pager, info2);
            return View(query);
        }

        public ActionResult StepOfNameList(int? id)
        {
            mainModel.appInfo.SiteTitle = "第二步，设定性别";
            ViewData["MainModel"] = mainModel;

            List<string> listOfTest = new List<string>();

            for (int i = 1; i<300;i++)
            {
                listOfTest.Add(i.ToString());
            }

            IQueryable<string> listIQ = from s in listOfTest.AsQueryable<string>() where Convert.ToInt32(s) % 5 == 0 select s;
            PagedList<string> orders = listIQ.ToPagedList(id ?? 1, 10);
            if (Request.IsAjaxRequest())
                return PartialView("UcOfNameList", orders);
            return View(orders);
         }

        public ActionResult StepOfCondition()
        {
            mainModel.appInfo.SiteTitle = "第二步，设定性别";
            ViewData["MainModel"] = mainModel;
            return View();
        }
        
        [HttpPost]
        public ActionResult StepOfCondition(string x)
        {
            return Redirect("StepOfNameList"); 
        }

        [HttpPost]
        public ActionResult StepOfNameList(string x)
        {
            return Redirect("StepOfCondition");
        }

    }
}
